<?php

class Empeval_Methods_Data_BaseUser {
	
	const NO_PHOTO = '/images/unknown_user.png';
	
	public $id;
	public $fname;
	public $lname;
	public $photo;
	public $company;
	public $email;
	public $phone;
	public $mobile;
	public $hasSuperior;
	public $isSuperior;
	/**
	 * 
	 * @var Empeval_Methods_Data_Role
	 */
	public $roles = array();
	/**
	 *
	 * @var Empeval_Methods_Data_Position
	 */
	public $position = null;
	/**
	 *
	 * @var Empeval_Methods_Data_Unit
	 */
	public $unit = null;
	
	public function __construct(EmpevalUsers $user, $onlyName=false, $withBonusGroup=false, $position=null) {
		$this->id = $user->getId();
		$this->fname = $user->getFname();
		$this->lname = $user->getLname();
		if (!$onlyName) {
			$this->photo = ($user->getPhoto() == '') ? self::NO_PHOTO : $user->getPhoto();
			$this->company = $user->getCompany();
			$this->email = $user->getEmail();
			$this->phone = $user->getPhone();
			$this->mobile = $user->getMobile();
			foreach ($user->getUserRolessRelatedByToUserId() as $userRole) {
				$this->roles[] = new Empeval_Methods_Data_Role($userRole->getRoles());
			}
			$userPosition = $user->getUserPositionss()->getFirst();
			if ($position instanceof EmpevalPositions) {
				$this->position = new Empeval_Methods_Data_Position($position, $withBonusGroup);
			}
			else if ($userPosition instanceof EmpevalUserPositions) {
				$this->position = new Empeval_Methods_Data_Position($userPosition->getPositions(), $withBonusGroup);
				$this->unit = new Empeval_Methods_Data_Unit($userPosition->getUnits());
				$this->hasSuperior = !($userPosition->getIsSuperior() == 1 && $userPosition->getUnits()->getParentId() == null);
				$this->isSuperior = (bool)$userPosition->getIsSuperior();
			}
		}
	}
	
}